package com.yubest.junit.thread;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 锁 对象
 *
 * @Author: hweiyu
 * @Date: 2022/11/1 15:56
 */
public class LockBean {

    private Lock lock = new ReentrantLock();

    public void noLockFun() {
        for (int i = 0; i < 100; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    public synchronized void syncLockFun() {
        for (int i = 0; i < 100; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
    }

    public void lockFun() {
        lock.lock();
        for (int i = 0; i < 100; i++) {
            System.out.print(i + " ");
        }
        System.out.println();
        lock.unlock();
    }

}
